package com.ellricky.newtv.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.bumptech.glide.Glide
import com.ellricky.newtv.R
import kotlinx.android.synthetic.main.dialog_store_code.*

class StoreCodeDialogFragment(val type: String, private val imageUrl: String) : DialogFragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.dialog_store_code, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        if (type == "wechat") {
            tv_title.text = "微信扫一扫"
            tv_hint.text = "请使用手机扫二维码添加微信客服"
        } else {
            tv_title.text = "课程材料包"
            tv_hint.text = "请使用手机扫二维码进入淘宝店购买"
        }
        Glide.with(this).load(imageUrl).into(iv_qr_cdoe)
    }

    override fun onStart() {
        super.onStart()
        val window = dialog?.window
        window?.also {
            val windowAttributes = it.attributes.apply {
                dimAmount = 0.4f
            }
            it.attributes = windowAttributes

            val width = resources.getDimensionPixelSize(R.dimen.store_shop_width)
            val height = resources.getDimensionPixelSize(R.dimen.store_shop_height)
            it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            it.setLayout(width, height)
        }
    }
}